from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# 设置浏览器选项
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument("--disable-extensions")

# 启动浏览器
driver = webdriver.Chrome()

# 打开淘宝网站
driver.get("https://www.taobao.com/")

# 等待页面加载完成
wait = WebDriverWait(driver, 10)
element = wait.until(EC.presence_of_element_located((By.ID, "q")))

# 搜索商品
search_box = driver.find_element(By.ID, "q")
search_box.send_keys("商品名称")
search_box.send_keys(Keys.RETURN)

# 等待搜索结果加载完成
element = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "J_MouserOnverReq")))

# 点击第一个商品
first_product = driver.find_element(By.CLASS_NAME, "J_MouserOnverReq")
first_product.click()

# 执行购买操作
# ...

# 关闭浏览器
driver.quit()